<?php
/**
 * crcl/base
 *
 * Copyright 2013 CRCL - André Sabosch - info@crcl.de
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace crcl\base\application;

interface IUrl
{
  /**
   * Returns project url from application data, depends on Tier
   *
   * @return  string  URL
   */
  public static function get();
}

class Url implements IUrl
{
  public static function get($sSubProject = \NULL, $sProject = \NULL)
  {
    if (\is_null($sSubProject))
    {
      $sSubProject = \crcl\base\Application::getSubProject();
    }
    if (\is_null($sProject))
    {
      $sProject = \crcl\base\Application::getProject();
      if (\crcl\base\Mvc::hasTheme())
      {
        $sProject = \crcl\base\Mvc::getTheme();
      }
    }
    $sResult = 'http://' .
      $sSubProject . '.' .
      $sProject . '.' .
      \crcl\base\Application::getVendor() . '.' .
      \strtolower(\crcl\base\Tier::get()) .
      '.crcl.de';

    if (\crcl\base\Tier::isProduction())
    {
      $sDomain = 'url';
      if (\crcl\base\Mvc::hasTheme())
      {
        $sDomain .= ':' . \crcl\base\Mvc::getTheme();
      }
      $sResult = \crcl\base\Config::reader()->get($sDomain, $sSubProject);
    }

    return $sResult;
  }
}